package com.ming.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.reggie.common.BaseContext;
import com.ming.reggie.common.R;
import com.ming.reggie.dto.DishDto;
import com.ming.reggie.pojo.Category;
import com.ming.reggie.pojo.Dish;
import com.ming.reggie.pojo.Employee;
import com.ming.reggie.pojo.Orders;
import com.ming.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("用户下单成功");
    }

    @GetMapping("/userPage")
    public R<Page> userPage(int page, int pageSize, String name) {
        Page<Orders> pageInfo = new Page<>(page, pageSize);
        Long userId = BaseContext.getCurrentId();
        LambdaQueryWrapper<Orders> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(Orders::getUserId,userId);
        lambdaQueryWrapper.orderByDesc(Orders::getOrderTime);
        orderService.page(pageInfo,lambdaQueryWrapper);
        return R.success(pageInfo);
    }
}
